@import '../../styles/var.less';

.k-image {
  position: relative;
  display: inline-block;
  text-align: center;
  line-height: 1;
  overflow: hidden;

  .k-image-img {
    width: 100%;
    height: auto;
    // max-height: 100%;
  }

  .k-image-loading {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background-color: var(--kui-color-mask);
    display: flex;
    color: var(--kui-color-border);
    align-items: center;
    justify-content: center;
  }

  .k-image-error {
    font-size: 50px;
    opacity: .3;
    color: var(--kui-color-disable-color);
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translateX(-50%) translateY(-50%);
  }

  .k-image-preview-mask {
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    font-size: 14px;
    color: #fff;
    background-color: var(--kui-color-mask);
    gap: 10px;
    cursor: pointer;
    transition: opacity .3s cubic-bezier(0.39, 0.575, 0.565, 1);
  }

  &:hover {
    .k-image-preview-mask {
      opacity: 1;
    }
  }
}

.k-image-preview {
  // transition: all .25s ease-in-out;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1001;
  display: flex;

  .k-image-preview-mask {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1001;
    height: 100%;
    background-color: var(--kui-color-mask);
  }

  .k-image-preview-wrap {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    flex: 1;
    overflow: hidden;
    outline: 0;
    -webkit-overflow-scrolling: touch;
    z-index: 1002;
    pointer-events: none;
    transition: all .3s;

    .k-image-preview-control {
      background-color: var(--kui-color-mask-30);
      display: flex;
      width: 100%;
      position: absolute;
      pointer-events: auto;
      bottom: 0;
      left: 0;
      z-index: 1;
      flex-direction: row-reverse;
      list-style: none;
      align-items: center;
      justify-content: center;
      margin: 0;
      padding: 0;

      path {
        stroke-width: 40px !important;
      }

      .k-image-preview-action {
        margin: 12px;
        color: #999;
        font-size: 28px;
        cursor: pointer;
        list-style: none;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 3px;

        &:hover {
          background-color: var(--kui-color-mask-30);
          color: #666;
        }
      }

      .k-image-preview-action-divider {
        position: relative;
        top: -.06em;
        display: inline-block;
        width: 1px;
        height: .9em;
        margin: 0 8px;
        vertical-align: middle;
        border-width: 1px 0 0;
        background-color: var(--kui-color-border);
      }

      .k-image-preview-action-rotate-left .k-icon {
        transform: rotateY(-180deg) rotate(45deg);
      }

      .k-image-preview-action-rotate-right .k-icon {
        transform: rotate(45deg);
      }

      .k-image-preview-action-disabled {
        opacity: .6;
        cursor: not-allowed;
      }
    }

    .k-image-preview-switch-left,
    .k-image-preview-switch-right {
      position: absolute;
      width: 44px;
      height: 44px;
      color: #999;
      font-size: 25px;
      border-radius: 50%;
      background-color: var(--kui-color-mask-30);
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 1;
      top: 50%;
      pointer-events: auto;
      cursor: pointer;

      &:hover {
        background-color: var(--kui-color-main);
        color: #fff;
      }

      &:active {
        background-color: var(--kui-color-main-active);
      }
    }

    .k-image-preview-switch-left {
      left: 10px;
      transform: rotate(-90deg);
    }

    .k-image-preview-switch-right {
      right: 10px;
      transform: rotate(90deg);
    }

    .k-image-preview-switch-disabled {
      cursor: not-allowed;
      opacity: .6;

      &:hover {
        background-color: var(--kui-color-mask-30);
      }
    }

    .k-image-preview-img-wrap {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      transition: transform .3s cubic-bezier(.215, .61, .355, 1) 0s;
      text-align: center;
      // overflow: hidden;
      pointer-events: none;

      &::before {
        display: inline-block;
        width: 0;
        height: 50%;
        content: '';
      }

      .k-image-preview-img {
        vertical-align: middle;
        user-select: none;
        pointer-events: auto;
        cursor: grab;
        transition: transform .3s ease-in-out;
        max-width: 100%;
        max-height: 100%;
      }

      video.k-image-preview-img {
        max-height: calc(100vh - 130px);
      }

      .k-image-preview-img-error {
        pointer-events: auto;
        width: 60%;
        height: 50%;
        background-color: var(--kui-color-mask-30);
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translateX(-50%) translateY(-50%);
        color: var(--kui-color-disable-color);
        // filter: blur(1px);
        font-size: 50px;
        text-align: center;
        display: flex;
        justify-content: center;
        border-radius: var(--kui-border-radius);
        align-items: center;
      }
    }
  }

  .k-image-preview-panel {
    background-color: var(--kui-color-mask-30);
    position: absolute;
    max-width: 512px;
    top: 0;
    right: 0;
    bottom: 0;
    padding: 20px;
    z-index: 1002;
    transform: translateX(0);
    opacity: 1;
    transition: all .3s;
    color: #fff;

    .k-image-preview-panel-action {
      position: absolute;
      left: 0;
      top: 50%;
      background-color: var(--kui-color-mask);
      border-radius: 0 5px 5px 0;
      padding: 15px 0;
      color: #fff;
      cursor: pointer;

      .k-icon {
        transform: rotate(90deg);
      }
    }
  }

  .k-image-preview-panel-hidden {
    transform: translateX(100%);
    opacity: 0;
  }
}

.k-image-panel-enter-active,
.k-image-panel-leave-active {
  transition: all .3s;
}

.k-image-group {
  display: inline-block;
}

@keyframes k-image-zoom {
  from {
    opacity: 0;
    transform: scale3d(.3, .3, 0) translateZ(0);
  }

  to {
    opacity: 1;
  }
}


.k-image-zoom-enter-active {
  animation: k-image-zoom .25s cubic-bezier(.78, .14, .15, .86);
}

.k-image-zoom-leave-active {
  animation: k-image-zoom .25s cubic-bezier(.78, .14, .15, .86) reverse;
}

.k-image-preview-loading {
  color: var(--kui-color-border);
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  width: 50px;
  font-size: 20px;
  height: 50px;
  border-radius: 10px;
  background: var(--kui-color-mask-30);
  display: flex;
  align-items: center;
  justify-content: center;
}